package com.kevin.springcloud.ribbonconsumer;

import com.netflix.discovery.DiscoveryClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class RibbonService {


    @Autowired
    private RestTemplate restTemplate;


//    @HystrixCommand(fallbackMethod = "myFallback")
    public String sayHello() {
        // http://服务提供者的serviceId/url
        return this.restTemplate.getForObject("http://HelloService/Hello/sayHello", String.class);
    }

    public String saySomething(String something){
        return this.restTemplate.getForObject("http://HelloService/Hello/saySomething/" + something, String.class);
    }

    public String myFallback() {
        return "Execute raw fallback: access service fail";
    }
}
